import pymysql
import os

# 提取文件中的 SQL 语句，按分号分割
sql_commands = """
-- Table structure for table `tb_spu_specification`
--





LOCK TABLES `tb_spu_specification` WRITE;
/*!40000 ALTER TABLE `tb_spu_specification` DISABLE KEYS */;
INSERT INTO `tb_spu_specification` VALUES (1,'2018-04-11 17:20:30.142577','2018-04-11 17:20:30.142657','屏幕尺寸',1),(2,'2018-04-11 17:21:57.862419','2018-04-11 17:21:57.862464','颜色',1),(3,'2018-04-11 17:22:04.687913','2018-04-11 17:22:04.687956','版本',1),(4,'2018-04-14 02:10:32.810681','2018-04-14 02:10:32.810728','颜色',2),(5,'2018-04-14 02:10:39.748266','2018-04-14 02:10:39.748314','内存',2),(6,'2018-04-14 03:04:39.450373','2018-04-14 03:04:39.450418','颜色',3),(7,'2018-04-14 03:04:50.182073','2018-04-14 03:04:50.182118','版本',3);
/*!40000 ALTER TABLE `tb_spu_specification` ENABLE KEYS */;
UNLOCK TABLES;

--

--

LOCK TABLES `tb_specification_option` WRITE;
/*!40000 ALTER TABLE `tb_specification_option` DISABLE KEYS */;
INSERT INTO `tb_specification_option` VALUES (1,'2018-04-11 17:22:55.126053','2018-04-11 17:22:55.126095','13.3英寸',1),(2,'2018-04-11 17:24:04.841221','2018-04-11 17:24:04.841265','15.4英寸',1),(3,'2018-04-11 17:24:23.862341','2018-04-11 17:24:23.862385','深灰色',2),(4,'2018-04-11 17:24:35.256820','2018-04-11 17:24:35.256868','银色',2),(5,'2018-04-11 17:25:04.607535','2018-04-11 17:25:04.607604','core i5/8G内存/256G存储',3),(6,'2018-04-11 17:25:15.969671','2018-04-11 17:25:15.969714','core i5/8G内存/128G存储',3),(7,'2018-04-11 17:25:35.025857','2018-04-12 07:12:08.090494','core i5/8G内存/512G存储',3),(8,'2018-04-14 02:11:12.231649','2018-04-14 02:11:12.231700','金色',4),(9,'2018-04-14 02:11:21.073811','2018-04-14 02:11:21.073917','深空灰',4),(10,'2018-04-14 02:11:27.692284','2018-04-14 02:11:27.692329','银色',4),(11,'2018-04-14 02:11:35.967113','2018-04-14 02:11:35.967163','64GB',5),(12,'2018-04-14 02:11:42.557263','2018-04-14 02:11:42.557354','256GB',5),(13,'2018-04-14 03:05:48.316724','2018-04-14 03:05:48.316835','钻雕金',6),(14,'2018-04-14 03:05:58.478640','2018-04-14 03:05:58.478689','钻雕蓝',6),(15,'2018-04-14 03:06:05.995609','2018-04-14 03:06:05.995652','玫瑰金',6),(16,'2018-04-14 03:06:37.587555','2018-04-14 03:06:37.587603','曜石黑',6),(20,'2018-04-14 03:07:15.727628','2018-04-14 03:07:15.727670','64GB',7),(21,'2018-04-14 03:07:23.480154','2018-04-14 03:07:23.480237','128GB',7);
/*!40000 ALTER TABLE `tb_specification_option` ENABLE KEYS */;
UNLOCK TABLES;

--


LOCK TABLES `tb_sku_specification` WRITE;
/*!40000 ALTER TABLE `tb_sku_specification` DISABLE KEYS */;
INSERT INTO `tb_sku_specification` VALUES (1,'2018-04-11 17:53:37.178101','2018-04-11 17:53:37.178148',1,1,1),(2,'2018-04-11 17:56:00.141036','2018-04-11 17:56:00.141078',4,1,2),(3,'2018-04-11 17:56:17.907973','2018-04-11 17:56:17.908017',7,1,3),(4,'2018-04-12 07:11:20.138634','2018-04-12 07:11:20.138677',1,2,1),(5,'2018-04-12 07:11:28.227056','2018-04-12 07:11:28.227099',3,2,2),(6,'2018-04-12 07:11:48.046789','2018-04-12 07:11:48.046885',7,2,3),(7,'2018-04-14 02:16:36.204410','2018-04-14 02:16:36.204453',8,3,4),(8,'2018-04-14 02:16:44.309888','2018-04-14 02:16:44.309972',11,3,5),(9,'2018-04-14 02:20:55.765324','2018-04-14 02:20:55.765377',8,4,4),(10,'2018-04-14 02:21:04.971106','2018-04-14 02:21:04.971155',12,4,5),(11,'2018-04-14 02:45:41.913322','2018-04-14 02:45:41.913372',9,5,4),(12,'2018-04-14 02:45:50.801926','2018-04-14 02:45:50.802005',11,5,5),(13,'2018-04-14 02:50:00.232648','2018-04-14 02:50:00.232694',9,6,4),(14,'2018-04-14 02:50:08.715882','2018-04-14 02:50:08.715927',12,6,5),(15,'2018-04-14 02:56:48.320934','2018-04-14 02:56:48.320980',10,7,4),(16,'2018-04-14 02:56:55.879794','2018-04-14 02:56:55.879839',11,7,5),(17,'2018-04-14 02:57:04.305406','2018-04-14 02:57:04.305462',10,8,4),(18,'2018-04-14 02:57:12.212999','2018-04-14 02:57:12.213047',12,8,5),(19,'2018-04-14 03:10:09.203601','2018-04-14 03:10:09.203646',13,9,6),(20,'2018-04-14 03:10:19.242994','2018-04-14 03:10:19.243421',20,9,7),(21,'2018-04-14 03:14:02.319574','2018-04-14 03:14:02.319621',13,10,6),(22,'2018-04-14 03:14:14.554189','2018-04-14 03:14:14.554237',21,10,7),(23,'2018-04-14 03:21:25.602470','2018-04-14 03:21:25.602519',14,11,6),(24,'2018-04-14 03:21:38.123239','2018-04-14 03:21:38.123285',21,11,7),(25,'2018-04-14 03:21:48.843531','2018-04-14 03:21:48.843577',14,12,6),(26,'2018-04-14 03:22:01.324252','2018-04-14 03:22:01.324321',20,12,7),(27,'2018-04-14 03:22:11.921568','2018-04-14 03:22:11.921613',15,13,6),(28,'2018-04-14 03:22:23.702276','2018-04-14 03:22:23.702323',20,13,7),(29,'2018-04-14 03:22:45.382268','2018-04-14 03:22:45.382313',15,14,6),(30,'2018-04-14 03:22:53.418091','2018-04-14 03:22:53.418147',21,14,7),(31,'2018-04-14 03:23:02.508118','2018-04-14 03:23:02.508186',16,15,6),(32,'2018-04-14 03:23:12.294204','2018-04-14 03:23:12.294255',20,15,7),(33,'2018-04-14 03:23:20.134049','2018-04-14 03:23:20.134095',16,16,6),(34,'2018-04-14 03:23:36.250798','2018-04-14 03:23:36.250844',21,16,7);
/*!40000 ALTER TABLE `tb_sku_specification` ENABLE KEYS */;
UNLOCK TABLES;
""".split(';')

try:
    with pymysql.connect(
        host='172.19.251.204',
        user='meiduo_user',
        password='123456',
        port=3306,
        database='meiduo_mall'
    ) as connection:
        with connection.cursor() as cursor:
            for command in sql_commands:
                command = command.strip()
                if command:
                    cursor.execute(command)
            print("All SQL commands executed successfully")
            # 提交事务
            connection.commit()
except pymysql.Error as err:
    print(f"An error occurred while executing SQL commands: {err}")
    # 出错时回滚事务
    if 'connection' in locals() and connection.open:
        connection.rollback()